package com.ccsu.mymarket.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ccsu.mymarket.entity.RechargeRecord;
import com.ccsu.mymarket.entity.message.Meta;
import com.ccsu.mymarket.entity.message.Result;
import com.ccsu.mymarket.jwt.UserLoginToken;
import com.ccsu.mymarket.service.RechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@UserLoginToken
@RestController
@RequestMapping("/records")
public class RechargeRecordController {
    private RechargeService rechargeService;

    public RechargeRecordController(@Autowired RechargeService rechargeService) {
        this.rechargeService = rechargeService;
    }

    @GetMapping("/page/{id}")
//    输入用户id
    public Result getRecord(@PathVariable Integer id) {
        List<RechargeRecord> recordList=rechargeService.list(new LambdaQueryWrapper<RechargeRecord>()
                .eq(RechargeRecord::getAccId,id));
        if (recordList==null)
            return new Result(new Meta(201,"暂无数据"),recordList);
        return new Result(new Meta(200,"查询成功！"),recordList);
    }

    @PostMapping("/add")
//    传入RechargeRecord实体类，时间和id除外
    public Result addRecord(@RequestParam Integer id,@RequestParam Double num){
        if (rechargeService.addReChargeRecord(id,num))
            return new Result(new Meta(200,"操作成功！"),null);
        return new Result(new Meta(500,"发生错误！"),null);
    }

}
